package com.atqinke.algorithm;

/**
 * @BelongsProject: BasicConnection
 * @BelongsPackage: com.atqinke.algorithm
 * @Author: NieHk
 * @CreateTime: 2022-08-16  17:21
 * @Description: 选择排序
 * @Version: 1.0
 */
public class SelectSort {
    public static void main(String[] args) {
        int[] newArray = new int[]{11,45, 77, 62, 55, 41, 37, 29, 11,72,13,489,132,89,78,791,13,45,96};
        selectSort(newArray);
        for (int i : newArray) {
            System.out.println(i);
        }
    }

    public static void selectSort(int[] array) {
        int length = array.length;
        for (int i = 0; i < length - 1; i++) {
            int min = i;
            for (int j = i + 1; j < length; j++) {
                if (array[min] > array[j]) {
                    min = j;
                }
            }
            int temp = array[i];
            array[i] = array[min];
            array[min] = temp;
        }
    }
}
